package ch.zbw.sysventory.agent.socketserver.handlers;

import java.io.DataOutputStream;

import org.apache.log4j.Logger;

public abstract class AbstractClientRequestHandler implements ClientRequestHandler {

	private Logger logger = Logger.getRootLogger();

	@Override
	public void handleClientRequest(String requestMessage, DataOutputStream output) throws Exception {
		// override this method in implementations !!
		this.sendResponseMessage(requestMessage, output, "");
	}

	protected void sendResponseMessage(String requestMessage, DataOutputStream output, String responseMessage) {
		try {
			byte[] responseBytes = responseMessage.getBytes();
			output.writeLong(responseBytes.length);
			output.write(responseBytes, 0, responseBytes.length);
			output.flush();
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}

}
